package lab03.test12;

import java.sql.*;

public class Test {
    public static void main(String[] args) {
//加载驱动
    Connection connection=null;
    Statement statement=null;
    ResultSet resultSet = null;
//表名字：t_users
    String sql="select * FROM t_users";
    String sql1="select * FROM t_users where username='admin'" ;
    String sql2="select * from t_users where username='admin' and password='123456'";
    String sql3="select * from t_users where register_datetime>10000000";
    try {
        Class.forName("com.mysql.jdbc.Driver");
        connection= DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                "root",
                "123456"
        );

        statement = connection.createStatement();
        resultSet = statement.executeQuery(sql);
        resultSet = statement.executeQuery(sql1);
        resultSet = statement.executeQuery(sql2);
        resultSet = statement.executeQuery(sql3);
        while (resultSet.next()) {
            System.out.println(resultSet.getString(1) + " " + resultSet.getString(2) + " " + resultSet.getString(3) + " " + resultSet.getString(4));
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            statement.close();
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

}
